package com.stock.stockana.ui.activities;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;

import com.stock.publiclib.utils.StringUtil;
import com.stock.stockana.R;
import com.stock.stockana.StockCenter;

import cn.jpush.android.api.JPushInterface;

/**
 * ---------------------------------------------------
 * Description: 打开应用后,最先启动的欢迎activity
 * Author: ljgsonx
 * Belong to: com.example.administrator.alldemos
 * Time: 2015/12/8 16:13
 * ---------------------------------------------------
 */
public class WelcomeActivityBackup extends AppCompatActivity {

    private static final int GO_HOME = 1000;

    // 延迟2秒
    private static final long SPLASH_DELAY_MILLIS = 2000;

    private Handler mHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            goHome();
            super.handleMessage(msg);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome_page);
        mHandler.sendEmptyMessageDelayed(GO_HOME, SPLASH_DELAY_MILLIS);
    }

    private void goHome() {
        String access_token = StockCenter.getUserDB().getAccessToken();
        Intent intent = null ;
        if (StringUtil.isBlank(access_token)) {
            intent = new Intent(this,SignInActivity.class);
        }else{
            intent = new Intent(this, MainActivity.class);
        }
        this.startActivity(intent);
        this.finish();
    }

    @Override
    protected void onResume() {
        super.onResume();
        JPushInterface.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        JPushInterface.onPause(this);
    }
}
